<?php
namespace app\admin\controller;

use app\common\model\User as UserModel;
use app\common\controller\AdminBase;
use think\Config;
use think\Db;

 class Checkstatus extends AdminBase
 {
    protected function initialize()
    {
        parent::initialize();
    }

	/*
	 * 状态验证
	 * @author ys
	 */
    public function index()
	{
		$id=input('get.id');
		$table=input('get.table');
		$field=input('get.field');
		$key=input('get.key');
		$data=[];
		if(empty($id) || empty($table) || empty($field) || empty($key)){
			$data['status']=5;
			return json($data);	
		}

		$data_info=Db::connect("db_config_aiqi")->name($table)->where($key,$id)->find();
		if($data_info[$field]==1){
		   $data_info=Db::connect("db_config_aiqi")->name($table)->where($key,$id)->setfield($field,0);
	       $data['status']=0;
		   $data['info']="更新成功";
	       return json($data);
		}else{	
		   $data_info=Db::connect("db_config_aiqi")->name($table)->where($key,$id)->setfield($field,1);
		   $data['status']=1;
		   $data['info']="更新成功";
	       return json($data);
		}
	}	
	/*
	 * 状态一键验证
	 * @author ys
	 */
	 public function allstatus()
	{
		$id=input('post.id/a');
	    $table=input('post.table');
		$field=input('post.field');
		$key=input('post.key');
		$all_status=input('post.all_status');
			$data=[];
		    if(empty($id) || empty($table) || empty($field) || empty($key) || !is_numeric($all_status)){
				$data['staus']=5;
				return json($data);	
			}
			$data_info=db($table)->where($key,'in',$id)->find();
	        if(!empty($data_info)){
			   $data_info=db($table)->where($key,'in',$id)->setfield($field,$all_status);
		       $data['status']=$all_status;
			   $data['info']="更新成功";
		       return json($data);
		 	}
	}
	/*
	 * 批量删除
	 * @author ys
	 */
	 public function alldelete()
	{
		$id=input('post.id/a');
		$table=input('post.table');
		$field=input('post.field');
		$key=input('post.key');
		$data=[];
	    if(empty($id) || empty($table) || empty($field) || empty($key)){
			$data['status']=5;	
			return json($data);	
		}
		$data_info=db($table)->where($key,'in',$id)->find();
         if(!empty($data_info)){
		   $data_info=db($table)->where($key,'in',$id)->delete();
	       $data['status']=0;
		   $data['info']="更新成功";
	       return json($data);
	
		 }
	
	} 
 }
?>